package com.travel.server.manager.impl.command.article;

import com.travel.common.util.CollectionUtil;
import com.travel.server.manager.dto.request.EmptyRequest;
import com.travel.server.manager.dto.response.article.QueryArticleClassEnumResponse;
import com.travel.server.manager.dto.response.article.QueryArticleClassEnumResponse.EnumItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.ArticleClassDal;
import com.travel.server.manager.impl.dal.PageDto;
import com.travel.server.manager.model.ArticleClassInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/25 10:42
 * @Desc:
 */
@Component
public class QueryArticleClassEnumCommand extends AbstractCommand<EmptyRequest, QueryArticleClassEnumResponse> {

    @Autowired
    private ArticleClassDal dal;

    @Override
    protected void checkInput(EmptyRequest request) {

    }

    @Override
    public QueryArticleClassEnumResponse handle(EmptyRequest request) {
        QueryArticleClassEnumResponse response = new QueryArticleClassEnumResponse();
        List<EnumItem> enumList = new ArrayList<>();
        PageDto<ArticleClassInfo> pageDto = dal.selectByPage(null, null);
        List<ArticleClassInfo> list = pageDto.getList();
        if(!CollectionUtil.isEmpty(list)){
            for(ArticleClassInfo info : list) {
                EnumItem item = new EnumItem();
                item.setId(info.getId());
                item.setName(info.getClassName());
                enumList.add(item);
            }
        }
        response.setEnumList(enumList);
        return response;
    }
}
